package cn.iocoder.yudao.module.system.dal.mysql.workorder;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.system.dal.dataobject.workorder.WorkOrderDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.workorder.vo.*;

/**
 * 工单管理 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface WorkOrderMapper extends BaseMapperX<WorkOrderDO> {

    default PageResult<WorkOrderDO> selectPage(WorkOrderPageReqVO reqVO) {
        List<String> storeMethod = new ArrayList<>();
        if(reqVO.getStorageMethod()!=null&&!reqVO.getStorageMethod().equals("0")){
            storeMethod.add(reqVO.getStorageMethod());
            storeMethod.add("0");
        }
        return selectPage(reqVO, new LambdaQueryWrapperX<WorkOrderDO>()
                .inIfPresent(WorkOrderDO::getStorageMethod, storeMethod)
                .inIfPresent(WorkOrderDO::getStorageMethod, reqVO.getStorageMethod2())
                .likeIfPresent(WorkOrderDO::getCustomerId, reqVO.getCustomerId())
                .likeIfPresent(WorkOrderDO::getCustomerName, reqVO.getCustomerName())
                .likeIfPresent(WorkOrderDO::getSupplierName, reqVO.getSupplierName())
                .likeIfPresent(WorkOrderDO::getProductName, reqVO.getProductName())
                .likeIfPresent(WorkOrderDO::getSpecification, reqVO.getSpecification())
                .likeIfPresent(WorkOrderDO::getPlanNumber, reqVO.getPlanNumber())
                .eqIfPresent(WorkOrderDO::getProductPrice, reqVO.getProductPrice())
                .eqIfPresent(WorkOrderDO::getProcessingTechnology, reqVO.getProcessingTechnology())
                .eqIfPresent(WorkOrderDO::getEstimatedUnitPrice, reqVO.getEstimatedUnitPrice())
                .eqIfPresent(WorkOrderDO::getProductArea, reqVO.getProductArea())
                .eqIfPresent(WorkOrderDO::getReworkUnitPrice, reqVO.getReworkUnitPrice())
                .eqIfPresent(WorkOrderDO::getProductSingleWeight, reqVO.getProductSingleWeight())
                .eqIfPresent(WorkOrderDO::getBillingMethod, reqVO.getBillingMethod())
                .eqIfPresent(WorkOrderDO::getProductMaterial, reqVO.getProductMaterial())
                .eqIfPresent(WorkOrderDO::getSalesFigures, reqVO.getSalesFigures())
                .eqIfPresent(WorkOrderDO::getTaxIncluded, reqVO.getTaxIncluded())
                .eqIfPresent(WorkOrderDO::getRack, reqVO.getRack())
                .eqIfPresent(WorkOrderDO::getRackNumber, reqVO.getRackNumber())
                .eqIfPresent(WorkOrderDO::getVoltage, reqVO.getVoltage())
                .eqIfPresent(WorkOrderDO::getFilmThickness, reqVO.getFilmThickness())
                .eqIfPresent(WorkOrderDO::getSingleHangingQuantity, reqVO.getSingleHangingQuantity())
                .eqIfPresent(WorkOrderDO::getChainSpeed, reqVO.getChainSpeed())
                .eqIfPresent(WorkOrderDO::getPackagingMethod, reqVO.getPackagingMethod())
                .eqIfPresent(WorkOrderDO::getSubgroup, reqVO.getSubgroup())
                .eqIfPresent(WorkOrderDO::getPicture, reqVO.getPicture())
                .betweenIfPresent(WorkOrderDO::getOrderDeliveryTime, reqVO.getOrderDeliveryTime())
                .eqIfPresent(WorkOrderDO::getWhiteItemsNum, reqVO.getWhiteItemsNum())
                .eqIfPresent(WorkOrderDO::getBlackItemsNum, reqVO.getBlackItemsNum())
                .eqIfPresent(WorkOrderDO::getQuantityStock, reqVO.getQuantityStock())
                .eqIfPresent(WorkOrderDO::getInitialQuantity, reqVO.getInitialQuantity())
                .eqIfPresent(WorkOrderDO::getInventoryQuantity, reqVO.getInventoryQuantity())
                .eqIfPresent(WorkOrderDO::getRackingQuantity, reqVO.getRackingQuantity())
                .eqIfPresent(WorkOrderDO::getHangingQuantity, reqVO.getHangingQuantity())
                .eqIfPresent(WorkOrderDO::getFinishedProductNum, reqVO.getFinishedProductNum())
                .eqIfPresent(WorkOrderDO::getSalesVolumes, reqVO.getSalesVolumes())
                .eqIfPresent(WorkOrderDO::getCpDefectNum, reqVO.getCpDefectNum())
                .eqIfPresent(WorkOrderDO::getBpDefectNum, reqVO.getBpDefectNum())
                .eqIfPresent(WorkOrderDO::getShouldReturn, reqVO.getShouldReturn())
                .leIfPresent(WorkOrderDO::getCreateTime, reqVO.getCreateTimeEnd())
                .geIfPresent(WorkOrderDO::getCreateTime, reqVO.getCreateTimeStart())
                .leIfPresent(WorkOrderDO::getUpdateTime, reqVO.getUpdateTimeEnd())
                .geIfPresent(WorkOrderDO::getUpdateTime, reqVO.getUpdateTimeStart())
                .leIfPresent(WorkOrderDO::getOrderDeliveryTime, reqVO.getOrderDeliveryTimeEnd())
                .geIfPresent(WorkOrderDO::getOrderDeliveryTime, reqVO.getOrderDeliveryTimeStart())
                .betweenIfPresent(WorkOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(WorkOrderDO::getId));
    }

    default PageResult<WorkOrderDO> statisticsPage(StatisticsPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<WorkOrderDO>()
                .likeIfPresent(WorkOrderDO::getCustomerName, reqVO.getCustomerName())
                .likeIfPresent(WorkOrderDO::getProductName, reqVO.getProductName())
                .likeIfPresent(WorkOrderDO::getSpecification, reqVO.getSpecification())
                .eqIfPresent(WorkOrderDO::getBillingMethod, reqVO.getBillingMethod())
                .eqIfPresent(WorkOrderDO::getSubgroup, reqVO.getSubgroup())
                .orderByDesc(WorkOrderDO::getId));
    }
}
